<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<!--[if lt IE 9]>
	<script type="text/javascript" src="lib/html5.js"></script>
	<script type="text/javascript" src="lib/respond.min.js"></script>
	<script type="text/javascript" src="lib/PIE_IE678.js"></script>
	<![endif]-->
	<link href="__PUBLIC__/css/H-ui.min.css" rel="stylesheet" type="text/css" />
	<link href="__PUBLIC__/css/H-ui.admin.css" rel="stylesheet" type="text/css" />
	<link href="__PUBLIC__/css/style.css" rel="stylesheet" type="text/css" />
	<link href="__PUBLIC__/lib/Hui-iconfont/1.0.6/iconfont.css" rel="stylesheet" type="text/css" />
	<link href="Tpl/Service/common/repairType/repairType.css" rel="stylesheet" type="text/css" />
	<!--[if IE 6]>
	<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
	<script>DD_belatedPNG.fix('*');</script>
	<![endif]-->
	<title>维修分类</title>
</head>
<body>
	<div class="pd-20">
		<div class="cl pd-5 bg-1 bk-gray mt-20">
			<span class="l">
				<a href="javascript:;" class="btn btn-danger radius repairTypeDelBat">
					<i class="Hui-iconfont">&#xe6e2;</i>
					批量删除
				</a>
				<a href="javascript:;" onclick="admin_repairType_add('添加维修分类','{:U('RepairType/add')}','','500')" class="btn btn-primary radius">
					<i class="Hui-iconfont">&#xe600;</i>
					添加维修分类
				</a>
			</span>
			<!--<span class="r">-->
				<!--共有数据： <strong>54</strong>-->
				<!--条-->
			<!--</span>-->
		</div>
		<table class="table table-border table-bordered table-bg" id="repairTypeTable">
			<thead>
				<tr>
					<!--<th scope="col" colspan="8">权限节点</th>-->
				</tr>
				<tr class="text-c">
					<th width="25">
						<input type="checkbox" name="" value=""></th>
					<th width="40">ID</th>
					<th width="100">分类名称</th>
					<th width="100">权限类型</th>
					<th width="50">上级分类</th>
					<th width="50">排序号</th>
					<th width="50">单位</th>
					<th width="50">单价</th>
					<th width="100">备注</th>
					<th width="100">操作</th>
				</tr>
			</thead>
			<tbody class="perTableTbody">
				<tr class="text-c">
					<td>
						<input type="checkbox" value="1" name=""></td>
					<td>1</td>
					<td>栏目添加</td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td>
						<a title="编辑" href="javascript:;" onclick="admin_repairType_edit('角色编辑','{:U('User/repairType_edit')}','1','','310')" class="ml-5" style="text-decoration:none">
							<i class="Hui-iconfont">&#xe6df;</i>
						</a>
						<a title="删除" href="javascript:;" onclick="admin_repairType_del(this,'1')" class="ml-5" style="text-decoration:none">
							<i class="Hui-iconfont">&#xe6e2;</i>
						</a>
					</td>
				</tr>
			</tbody>
		</table>
		
	</div>
	<script type="text/javascript" src="__PUBLIC__/lib/jquery/1.9.1/jquery.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/lib/layer/2.1/layer.js"></script>
	<script type="text/javascript" src="__PUBLIC__/lib/laypage/1.2/laypage.js"></script>
	<script type="text/javascript" src="__PUBLIC__/lib/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/H-ui.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/H-ui.admin.js"></script>
	<script type="text/javascript" src="__PUBLIC__/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			var table=$("#repairTypeTable");
			table.dataTable({

				"ajax":function(data,callback,setting){
					var page = table.api().page.info();
					$.post("/index.php?m=Service&c=RepairType&a=lst",{pageIndex:page.page,pageSize:page.length},function(data,status){
						console.log(data);
						callback(data);
					});
				},

 				 "pageLength":10,
  				"ordering":false,
  				"columns":[
  				{"data":"id"},
  				{"data":"id"},
  				{"data":"name"},
  				{"data":"level"},
  				{"data":"pid_name"},
  				{"data":"sort"},
  				{"data":"unit"},
  				{"data":"price"},
  				{"data":"remark"},
  				{"data":"id"},
  				],
  				"columnDefs":[
  				{
  					"targets":0,
  					"data":"id",
  					"render":function(data,type,full,meta){
  						return '<input type="checkbox" value="'+data+'" name="type_id">';
  					}

  				},
  				{
  					"targets":3,
  					"data":"level",
  					"render":function(data,type,full,meta){
  						var str="";
  						switch(data){
  							case "1":
  							str="1级分类";
  							break;
  							case "2":
  							str="2级分类";
  							break;
  							case "3":
  							str="3级分类";
  							break;
  							case "4":
  							str="4级分类";
  							break;
  						}
  						return str;
  					}
  				},
  				{
  					"targets":9,
  					"data":"id",
  					"render":function(data,type,full,meta){
  						var poStr='<a title="编辑" href="javascript:;" uid="'+data+'" class="ml-5 repairTypeEdit" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a><a title="删除" href="javascript:;" uid="'+data+'" class="ml-5 repairTypeDel uid-'+data+'" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>';
  						return(poStr);
  					}

  				},
  				],
  			"fnCreatedRow":function(row,data,index){
  				//row 表示当前tr，data表示当前行的元素对象，index表示当前tr索引
  				$(row).find("td").eq(2).css("textAlign","left")
  				switch(data['level']){
  					case "1":
  							$(row).find("td").eq(2).css("paddingLeft","10px");
  							break;
  					case "2":
  							$(row).find("td").eq(2).css("paddingLeft","50px");
  							break;
  					case "3":
  							$(row).find("td").eq(2).css("paddingLeft","70px");
  							break;
  				}
  			},
			"bPaginate": true, //翻页功能
			// "processing": true,
        	// "serverSide": true,//服务器模式
        			// 	"infoCallback": function( settings, start, end, max, total, pre ) {
  //  				table.DataTable().ajax.reload();
  // },

        });
});

//权限复选框
// $(document).on("click",".perTableTbody checkbox");

/*
参数解释：
title	标题
url		请求的url
id		需要操作的数据id
w		弹出层宽度（缺省调默认值）
h		弹出层高度（缺省调默认值）
*/
/*管理员-权限-添加*/
function admin_repairType_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*管理员-权限-编辑*/
$(document).on("click",".repairTypeEdit",function(){
	var id=$(this).attr("uid");
	layer.open({
		type: 2,
		area: ['500px', '600px'],
		fix: false, //不固定
		maxmin: true,
		shade:0.4,
		title: "权限编辑",
		content:'/index.php?m=Service&c=RepairType&a=edit'+'&id='+id,
	});
});

/*管理员-权限-删除*/
$(document).on("click",".repairTypeDel",function(e){
	
	var id=$(this).attr("uid");
	layer.confirm('确定删除该分类么？',function(index){
		// console.log(e);
		perDel(id);
	});
});


// 管理员-权限-批量删除
$(document).on("click",".repairTypeDelBat",function(e){
		repairTypeId=[];
		var repairTypeName="";
		$("input[name='repairType']:checked").each(function(){
			repairTypeId.push($(this).val());
			 repairTypeName+=$(this).val()+',';
		});
		repairTypeName='你确定删除id为：'+repairTypeName+'的权限么？';
		layer.confirm(repairTypeName,function(){
			perDel(repairTypeId);
			
		});

});

// 删除函数
function perDel(id){

	$.post("/index.php?m=Service&c=RepairType&a=delete",{id:id.toString()},function(){
		var table=$("#repairTypeTable");
		console.log(id);
		if(typeof(id)=='string'){
			table.DataTable().row($(".uid-"+id).parents('tr')).remove().draw(false);
		}else{
			for(var i=0;i<id.length;i++){
			table.DataTable().row($(".uid-"+id[i]).parents('tr')).remove().draw(false);
			}
		}
		
		layer.msg('已删除!',{icon:1,time:1000});
	});
}
</script>
</body>
</html>